package sketch.icse11nier;


import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import sketch.ounit.Values;
import sketch.specs.annotation.TestSketch;
import junit.framework.TestCase;

public class Z_Sketch_SpecifyStatements extends TestCase {
	
	@TestSketch
	public void testAddRemove() {
		List l = new LinkedList();
		{/*@ChooseOne*/ l.add(l); l.add(2); }
		{/*@ChooseAllOrNone*/ l.clear();}
	}
	
	@TestSketch
	public void testAdd() {
		List l = new LinkedList();
		int i = Values.choose(1, 2, 3);
		{/*@Repeat*/
			l.add(i);
		}
	}
	
	@TestSketch
	public void testIterator() {
		List l = new LinkedList();
		Iterator it = l.iterator();
		{/*@TryCatch*/
			{/*@ChooseOne*/
				it.next();
				it.remove();
			}
		}
	}
	
	@TestSketch
	public void testConstructor() {
		try {
			int i = Values.choose(0, -1);
			{/*@ChooseOne*/
				new CircularFifoBuffer(i);
				new CircularFifoBuffer(null);
			}
			fail();
		} catch (IllegalArgumentException e) {
			//ok here
		}
		
	}

	//to avoid dependence on apache collections, i use a mock object here
	public class CircularFifoBuffer {
		public CircularFifoBuffer(int i) {
			if(i <=0 ) {
				throw new IllegalArgumentException();
			}
		}
		
		public CircularFifoBuffer(Collection collection) {
			if (collection == null) {
				throw new IllegalArgumentException();
			}
		}
	}
}
